import pymysql
import csv

conn = pymysql.connect(host='localhost', user='root', password='123456',
                      db='xian_web', charset='utf8mb4')

with conn.cursor() as cursor:
    cursor.execute("SELECT * FROM warehouse_xian_poi")
    with open('warehouse_xian_poi.csv', 'w', encoding='utf-8', newline='') as f:
        writer = csv.writer(f)
        writer.writerow([i[0] for i in cursor.description])  # 写列名
        writer.writerows(cursor)